/*******************************************************************************
 * @file Logging.h
 * Collection of macros for easier access to the log system.
 * 
 * @package Logging.
 * 
 * @author Martin Komischke
 * @date 28/12/2008 13:50:21
 * @version 0.1
 ******************************************************************************/

#ifndef __LOGGING_H_INCLUDED__
#define __LOGGING_H_INCLUDED__

#include <exception>

#include "Logger.h"
#include "Tracer.h"

#ifdef _DEBUG
#ifdef LOG_DBG
#warning "Macro LOG_DBG will be redefined!"
#endif
#define LOG_DBG(msg)														\
{																			\
	boost::lock_guard<boost::mutex> lock(Logging::FilteredLogger::Mutex()); \
	Logging::FilteredLogger::Get("DEBUG") <<								\
		Logging::CIndexDateTime().ToString() << " TID:" <<					\
		Logging::Utils::GetCurrentThreadId() << " " <<						\
		Logging::CLocation(__FILE__, __LINE__).ToString() <<				\
		"DEBUG " <<	msg << std::endl;										\
}

#ifdef LOG_INFO
#warning "Macro LOG_INFO will be redefined!"
#endif
#define LOG_INFO(msg)														\
{																			\
	boost::lock_guard<boost::mutex> lock(Logging::FilteredLogger::Mutex()); \
	Logging::FilteredLogger::Get("INFO") <<									\
		Logging::CIndexDateTime().ToString() << " TID:" <<					\
		Logging::Utils::GetCurrentThreadId() << " " <<						\
		Logging::CLocation(__FILE__, __LINE__).ToString() <<				\
		"INFO " <<	msg << std::endl;										\
		std::cout << msg << std::endl;										\
}

#ifdef LOG_WARNING
#warning "Macro LOG_WARNING will be redefined!"
#endif
#define LOG_WARNING(msg)													\
{																			\
	boost::lock_guard<boost::mutex> lock(Logging::FilteredLogger::Mutex()); \
	Logging::FilteredLogger::Get("WARNING") <<								\
		Logging::CIndexDateTime().ToString() << " TID:" <<					\
		Logging::Utils::GetCurrentThreadId() << " " <<						\
		Logging::CLocation(__FILE__, __LINE__).ToString() <<				\
		"WARNING " <<	msg << std::endl;									\
}

#ifdef LOG_ERROR
#warning "Macro LOG_ERROR will be redefined!"
#endif
#define LOG_ERROR(msg)														\
{																			\
	boost::lock_guard<boost::mutex> lock(Logging::FilteredLogger::Mutex()); \
	Logging::FilteredLogger::Get("ERROR") <<								\
		Logging::CIndexDateTime().ToString() << " TID:" <<					\
		Logging::Utils::GetCurrentThreadId() << " " <<						\
		Logging::CLocation(__FILE__, __LINE__).ToString() <<				\
		"ERROR " <<	msg << std::endl;										\
}

#ifdef TRACE_FUNC
#warning "Macro TRACE_FUNC will be redefined!"
#endif
#ifdef _DEBUG
#define TRACE_FUNC(func) Logging::CTracer tracer(__FILE__, __LINE__, func)
#else
#define TRACE_FUNC(func) Logging::CTracer tracer(__FILE__, __LINE__, "Function")
#endif

#ifdef TRACE
#waring "Macro TRACE will be redefined!"
#endif
#ifdef _DEBUG
#define TRACE(msg)															\
{																			\
	boost::lock_guard<boost::mutex> lock(Logging::FilteredLogger::Mutex()); \
	Logging::FilteredLogger::Get("TRACE") <<								\
		Logging::CIndexDateTime().ToString() << " TID:" <<					\
		Logging::Utils::GetCurrentThreadId() << " " <<						\
		"TRACE " <<	msg << std::endl;										\
}
#else
#define TRACE(msg)
#endif

#ifdef TRACE_ERROR
#waring "Macro TRACE_ERROR will be redefined!"
#endif
#define TRACE_ERROR(msg)													\
{																			\
	boost::lock_guard<boost::mutex> lock(Logging::FilteredLogger::Mutex()); \
	Logging::FilteredLogger::Get("ERROR") <<								\
		Logging::CIndexDateTime().ToString() << " TID:" <<					\
		Logging::Utils::GetCurrentThreadId() << " " <<						\
		"ERROR " <<	msg << std::endl;										\
}

#else

#ifdef LOG_DBG
#warning "Macro LOG_DBG will be redefined!"
#endif
#ifdef _DEBUG
#define LOG_DBG(msg)
#else
#define LOG_DBG(msg)
#endif

#ifdef LOG_INFO
#warning "Macro LOG_INFO will be redefined!"
#endif
#define LOG_INFO(msg) std::cout << msg << std::endl;

#ifdef LOG_WARNING
#warning "Macro LOG_WARNING will be redefined!"
#endif
#define LOG_WARNING(msg)

#ifdef LOG_ERROR
#warning "Macro LOG_ERROR will be redefined!"
#endif
#define LOG_ERROR(msg)

#ifdef TRACE_FUNC
#warning "Macro TRACE_FUNC will be redefined!"
#endif
#define TRACE_FUNC(func)

#ifdef TRACE
#waring "Macro TRACE will be redefined!"
#endif
#define TRACE(msg)

#ifdef TRACE_ERROR
#waring "Macro TRACE_ERROR will be redefined!"
#endif
#define TRACE_ERROR(msg)													\
{																			\
	Logging::FilteredLogger::Get("ERROR") <<								\
		Logging::CIndexDateTime().ToString() << " TID:" <<					\
		Logging::Utils::GetCurrentThreadId() << " " <<						\
		"ERROR " <<	msg << std::endl;										\
}

#endif

#endif  /* __LOGGING_H_INCLUDED__ */
